package com.grape.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.grape.constants.Constants;
import com.grape.utils.StringUtils;
import com.grape.utils.ThreadLocalUtil;
import com.grape.vo.BaseVo;
import com.grape.wrapper.BaseWrapper;
import com.grape.domain.MemberRechargeRecord;
import com.grape.mapper.MemberRechargeRecordMapper;
import com.grape.service.IMemberRechargeRecordService;
import lombok.AllArgsConstructor;
import org.apache.logging.log4j.util.Strings;
import org.slf4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 *
 * 会员充值记录表 服务实现类
 *
 * @author      putao
 * @email       2628279194@qq.com
 */
@Service
@AllArgsConstructor
@Transactional(readOnly = true)
public class MemberRechargeRecordServiceImpl extends ServiceImpl<MemberRechargeRecordMapper, MemberRechargeRecord> implements IMemberRechargeRecordService {

    private final MemberRechargeRecordMapper memberRechargeRecordMapper;

    private static final Logger logger = org.slf4j.LoggerFactory.getLogger(MemberRechargeRecordServiceImpl.class);

    /**
     * 分页
     * @param baseVo    统一分页对象
     * @return          会员充值记录表集合
     */
    @Override
    public List<MemberRechargeRecord> listData(BaseVo baseVo) {
        QueryWrapper<MemberRechargeRecord> wrapper = new BaseWrapper<MemberRechargeRecord>().init();
        wrapper.like(Strings.isNotBlank(baseVo.getSearch()), Constants.NAME, baseVo.getSearch())
                .eq(StringUtils.isNotBlank(baseVo.getColumnName()) && StringUtils.isNotBlank(baseVo.getSelect()), baseVo.getColumnName(), baseVo.getSelect());
        orderByModifyTimeDesc(wrapper);
        return this.list(wrapper);
    }

    /**
     * 自定义分页
     * @param   baseVo      统一分页对象
     */
    @Override
    public void pageListCustom(BaseVo baseVo) {
        String userId = ThreadLocalUtil.getUserId();
        QueryWrapper<MemberRechargeRecord> qw = new QueryWrapper<MemberRechargeRecord>().eq(Constants.USER_ID, userId)
                .orderByDesc(Constants.CREATE_TIME);
        this.memberRechargeRecordMapper.selectList(qw);
    }

    /**
     * 修改
     * @param memberRechargeRecord 会员充值记录表对象
     */
    @Override
    @Transactional(readOnly = false, rollbackFor = Exception.class)
    public void updateData(MemberRechargeRecord memberRechargeRecord) {
        this.baseUpdate(memberRechargeRecord);
    }

    /**
     * 新增
     * @param       memberRechargeRecord 会员充值记录表对象
     * @return      会员充值记录表对象
     */
    @Override
    @Transactional(readOnly = false, rollbackFor = Exception.class)
    public MemberRechargeRecord insertData(MemberRechargeRecord memberRechargeRecord) {
        return this.baseInsert(memberRechargeRecord);
    }

    /**
     * 删除
     * @param id    单据id
     * @return      删除条数
     */
    @Override
    @Transactional(readOnly = false, rollbackFor = Exception.class)
    public int deleteData(String id) {
        return this.baseDelete(id);
    }

    /**
     * 根据id查询详情
     * @param       id  单据id
     * @return      会员充值记录表对象
     */
    @Override
    public MemberRechargeRecord detail(String id) {
        return this.getByIdForDelFlag(id);
    }
}
